package com.joysw.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.joysw.R;
import com.joysw.view.PagerSlidingTabStrip;
import com.joysw.view.TitleBarView;

/**
 * @Title: FxjlFragment.java
 * @Package com.joysw.ui.fragment
 * @Description: 分享记录
 * @author LIMINGYAN
 * @date 2015年3月28日 下午9:29:56
 * @version V1.0
 */
public class FxjlFragment extends BaseFragment {
	private static final String TAG = "FxjlFragment";
	private Context mContext;
	private View mBaseView;

	@InjectView(R.id.fxjl_title_bar)
	TitleBarView mTitleBar;

	// tab选项卡控制类
	@InjectView(R.id.fxjl_tabs)
	PagerSlidingTabStrip mTabs;

	@InjectView(R.id.fxjl_pager)
	ViewPager mPager;

	private FxjlTabOneFrgment oneFrgment;//分享的动态页面
	private FxjlTabTwoFrgment twoFrgment;//分享的链接页面
	private MyPagerAdapter mAdapter;
	String[] titles = { "分享的动态", "分享的链接" };

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContext = getActivity();
		mBaseView = inflater.inflate(R.layout.fragment_fxjl, container, false);
		ButterKnife.inject(this, mBaseView);
		initView();

		return mBaseView;
	}

	private void initView() {
		mTitleBar.setCommonTitle(View.GONE, View.VISIBLE, View.GONE);
		mTitleBar.setTitleText(R.string.fragment_fxjl_title);
		
		mAdapter = new MyPagerAdapter(getChildFragmentManager(),titles);
		mPager.setAdapter(mAdapter);
		
		mTabs.setViewPager(mPager);
	}

	public class MyPagerAdapter extends FragmentPagerAdapter {

		String[] _titles;

		public MyPagerAdapter(FragmentManager fm, String[] titles) {
			super(fm);
			_titles = titles;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return _titles[position];
		}

		@Override
		public int getCount() {
			return _titles.length;
		}

		@Override
		public Fragment getItem(int position) {
			switch (position) {
			case 0:
				if (oneFrgment == null) {
					oneFrgment = new FxjlTabOneFrgment();
				}
				return oneFrgment;
			case 1:
				if (twoFrgment == null) {
					twoFrgment = new FxjlTabTwoFrgment();
				}
				return twoFrgment;
			default:
				return null;
			}
		}

	}
	
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
}
